<?php 
	$data['title'] = '区域管理-区域管理';
	$data['site_url'] = site_url('manager/area/');
	$data['csses'] = array('js/plug/treeTable/css/jquery.treeTable.css');
	$data['jses'] = array('js/plug/treeTable/js/jquery.treeTable.js');
	$this->load->view('manager/header',$data);
?>
<div class="mainBody">
	<div class="tabTitle">
		<ul>
			<li <?php if($action == 'list') echo 'class="current"'?>><a href="<?php echo site_url('manager/area/index/');?>">区域列表</a></li>
			<li <?php if($action == 'add') echo 'class="current"'?> title="新增区域"><a href="<?php echo site_url('manager/area/show_add/');?>" title="新增区域">新增区域</a></li>
			<?php if($action == 'edit') 
				echo '<li class="current" title="编辑区域">编辑区域</li>';
			?>
		</ul>
	</div>
	<?php if($action == 'list'){?>
	<script type="text/javascript">
		$(document).ready(function($) {
		    $("#areaTable").treeTable();
		    // Make visible that a row is clicked
		    $("table#areaTable tbody tr").live('mousedown',function() {
		      $("tr.selected").removeClass("selected"); // Deselect currently selected rows
		      $(this).addClass("selected");
		    });
			/*
		    // Make sure row is selected when span is clicked
		    $("table#dnd-example tbody tr span").mousedown(function() {
		      $($(this).parents("tr")[0]).trigger("mousedown");
		    });
		    */
//		    $('.WinBox').colorbox();
		});
	</script>
	<table id="areaTable" border="0" cellpadding="0" cellspacing="0">
		<thead>
			<tr>
				<th>名称</th>
				<th width="100">排序</th>
				<th width="100">子类数量</th>
				<th width="200">操作</th>
			</tr>
		</thead>
		<tbody>
			<?php 
			function areaTree($list) {
				if(isset($list))
					foreach ($list as $item) {
						echo "<tr id=node_".$item['id']." class=".($item['sub_num']>0?"parent":"").($item['parentid']!=0?"child-of-node_".$item['parentid']:"").">
								<td><input type='checkbox' value='".$item['id']."'/><span class=".($item['sub_num']>0?'folder':'file').">".$item['name']."</span></td>
								<td>".$item['sort']."</td>
								<td>".$item['sub_num']."</td>
								<td>
									<a class='iconAdd' href=".site_url('manager/area/show_add/'.$item['id'])." title=添加子类> + </a>
									<a class='iconEdit' href=".site_url('manager/area/show_edit/'.$item['id'])." title=编辑></a>".
									($item['sub_num'] == 0?
									"<a class='op_ajax iconDel' href=".site_url('manager/area/delete/'.$item['id'])." title='删除'></a>":
									"<a class=iconNull></a>").
								"</td>
							</tr>";
						if(isset($item['childs'])){
							areaTree($item['childs']);
						}
					}
			}
			areaTree($list);
			?>
		</tbody>
	</table>
	<?php }else if($action == 'add' || $action == 'edit'){
		$this->load->view('form_view',$data);
	}?>
</div>
<?php $this->load->view('manager/footer');?>